/**
 * Created by Weiler on 2017/4/13.
 */
var cartKey = 'lt'; //购物车cookie的键
$.cartCookie = function (data, cartFun) {
    var oldData = store.get(cartKey);
    var newData = oldData != undefined ? oldData : [];
    var check = true;
    if (cartFun) {
        for (var x in newData)
        {
            if(newData[x].id == data.id)
            {
                check = false;
                newData[x].num = Number(newData[x].num) + 1;
            }
        }
        if (oldData == null || check) {
            newData.push(data);
        }
    } else {
        if (oldData == null)
            return false;
        for (var x in newData)
        {
            if(newData[x].id == data.id)
            {
                newData[x].num = Number(newData[x].num) - 1;
                if (newData[x].num == 0) {
                    newData.splice(x,1);
                }
            }
        }
        if (newData.length == 0)
        {
            store.remove(cartKey);
            return true;
        }
    }
    store.set(cartKey, newData);
    return true;
};